package com.jiuzhou.guanwang.jzcp.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jiuzhou.guanwang.jzcp.R;
import com.jiuzhou.guanwang.jzcp.bean.GroupResultBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WorldCupGroupAdapter extends BaseAdapter {
    private final Context mContext;
    private List<GroupResultBean.ContentX.Rounds.Content.DataX> mData;


    public WorldCupGroupAdapter(Context context) {
        this.mContext = context;
    }

    public int getCount() {
        return this.mData == null ? 0 : this.mData.size();
    }

    public Object getItem(int position) {
        return mData.get(position);
    }

    public long getItemId(int position) {
        return (long) position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_group, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
         TeamAdapter adapter = new TeamAdapter(mContext,mData.get(position).getData());
        //特色基金列表
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        viewHolder.rvTeam.setFocusable(false);
        viewHolder.rvTeam.setLayoutManager(layoutManager);
        viewHolder.rvTeam.setAdapter(adapter);
        viewHolder.tvGroup.setText(mData.get(position).getName());
        return convertView;
    }

    public void setData(List<GroupResultBean.ContentX.Rounds.Content.DataX> data) {
        this.mData = data;
        notifyDataSetChanged();
    }

    static class ViewHolder {
        @BindView(R.id.tv_group)
        TextView tvGroup;
        @BindView(R.id.rv_team)
        RecyclerView rvTeam;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}